home *** CD-ROM | disk | FTP | other *** search
/ CD Actual Thematic 29 / CDT29.iso / e-Mail / WorldClient Pro 2.2.3 / wcsetup.exe / WEBHELP.ZIP / hhapplet / TabButton.class (.txt) < prev    next >
Encoding:
Java Class File  |  1999-10-21  |  3.8 KB  |  201 lines

  1. package hhapplet;
  2.  
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Dimension;
  6. import java.awt.Font;
  7. import java.awt.FontMetrics;
  8. import java.awt.Graphics;
  9. import java.awt.Rectangle;
  10. import java.awt.image.ImageObserver;
  11.  
  12. public class TabButton extends CanvasButton {
  13.    protected String label;
  14.    protected int x_offset = -1;
  15.    protected int y_offset = -1;
  16.    protected Font active;
  17.    protected Font inactive;
  18.    protected int tab_x;
  19.    protected int tab_y;
  20.    protected int tab_width;
  21.    protected int tab_height;
  22.    protected boolean m_bDrawLeft = true;
  23.    protected boolean m_bDrawRight = true;
  24.    protected boolean m_bCenterBroken = false;
  25.  
  26.    protected void centerText(Font var1) {
  27.       Rectangle var2 = ((Component)this).bounds();
  28.       FontMetrics var3 = ((Component)this).getFontMetrics(var1);
  29.       int var4 = var3.stringWidth(this.label);
  30.       int var5 = var3.getMaxAscent();
  31.       this.y_offset = var2.height - var5;
  32.       this.y_offset = this.y_offset / 2 + var5;
  33.       this.x_offset = var2.width - var4;
  34.       this.x_offset /= 2;
  35.       if (this.m_bCenterBroken && !((Component)this).isEnabled()) {
  36.          this.x_offset += 3;
  37.       }
  38.  
  39.    }
  40.  
  41.    public void reshape(int var1, int var2, int var3, int var4) {
  42.       super.reshape(var1, var2, var3, var4);
  43.       this.tab_x = var1;
  44.       this.tab_y = var2;
  45.       this.tab_width = var3;
  46.       this.tab_height = var4;
  47.       this.centerText(((Component)this).getFont());
  48.    }
  49.  
  50.    public TabButton(String var1) {
  51.       int var2 = WebHelp.GetFontSize();
  52.  
  53.       for(this.active = new Font(WebHelp.GetFontName(), 1, var2); this.active.getSize() != var2 && var2 < WebHelp.GetFontSize() + 10; this.active = new Font(WebHelp.GetFontName(), 1, var2)) {
  54.          ++var2;
  55.       }
  56.  
  57.       this.inactive = new Font(WebHelp.GetFontName(), 0, var2);
  58.       ((Component)this).setFont(this.inactive);
  59.       this.label = var1;
  60.       if (System.getProperty("java.vendor").startsWith("Netscape") && System.getProperty("os.name").startsWith("Windows 95")) {
  61.          try {
  62.             String var3 = System.getProperty("java.version");
  63.             if (var3.startsWith("1.02")) {
  64.                this.m_bCenterBroken = true;
  65.             }
  66.  
  67.             Integer var4 = new Integer(var3.substring(0, 1));
  68.             Integer var5 = new Integer(var3.substring(2, 3));
  69.             Integer var6 = new Integer(var3.substring(4, 5));
  70.             if (var4 <= 1 && var5 <= 1 && var6 <= 2) {
  71.                this.m_bCenterBroken = true;
  72.                return;
  73.             }
  74.          } catch (Exception var7) {
  75.          }
  76.       }
  77.  
  78.    }
  79.  
  80.    public void paint(Graphics var1) {
  81.       var1.setColor(((Component)this).getBackground());
  82.       var1.fillRect(0, 0, ((Component)this).bounds().width, ((Component)this).bounds().height);
  83.       if (super.img != null) {
  84.          var1.drawImage(super.img, 2, 2, (ImageObserver)null);
  85.       } else if (this.label != null) {
  86.          this.centerText(((Component)this).getFont());
  87.          var1.setColor(((Component)this).getForeground());
  88.          var1.setFont(((Component)this).getFont());
  89.          var1.drawString(this.label, this.x_offset, this.y_offset);
  90.       }
  91.  
  92.       this.paintBorderOut(var1);
  93.    }
  94.  
  95.    public void paintBorderOut(Graphics var1) {
  96.       Rectangle var2 = ((Component)this).bounds();
  97.       if (!((Component)this).isEnabled()) {
  98.          var1.setColor(Color.white);
  99.          var1.drawLine(2, 0, var2.width - 3, 0);
  100.          var1.drawLine(1, 1, 1, 1);
  101.          var1.drawLine(0, 2, 0, var2.height - 1);
  102.          var1.setColor(Color.white);
  103.          var1.drawLine(2, 0, var2.width - 3, 0);
  104.       } else if (this.m_bDrawLeft) {
  105.          var1.setColor(Color.white);
  106.          var1.drawLine(2, 3, var2.width - 3, 3);
  107.          var1.drawLine(1, 4, 1, 4);
  108.          var1.drawLine(0, 5, 0, var2.height - 1);
  109.       } else {
  110.          var1.setColor(Color.white);
  111.          var1.drawLine(0, 3, var2.width - 3, 3);
  112.       }
  113.  
  114.       if (!((Component)this).isEnabled()) {
  115.          var1.setColor(Color.darkGray);
  116.          var1.drawLine(var2.width - 2, 2, var2.width - 2, var2.height - 1);
  117.          var1.setColor(Color.black);
  118.          var1.drawLine(var2.width - 2, 1, var2.width - 2, 1);
  119.          var1.drawLine(var2.width - 1, 2, var2.width - 1, var2.height - 1);
  120.       } else if (this.m_bDrawRight) {
  121.          var1.setColor(Color.darkGray);
  122.          var1.drawLine(var2.width - 2, 5, var2.width - 2, var2.height - 1);
  123.          var1.setColor(Color.black);
  124.          var1.drawLine(var2.width - 2, 4, var2.width - 2, 4);
  125.          var1.drawLine(var2.width - 1, 5, var2.width - 1, var2.height - 1);
  126.       } else {
  127.          var1.setColor(Color.white);
  128.          var1.drawLine(2, 3, var2.width - 1, 3);
  129.       }
  130.  
  131.       if (((Component)this).isEnabled()) {
  132.          var1.setColor(Color.white);
  133.          var1.drawLine(0, var2.height - 1, var2.width - 1, var2.height - 1);
  134.          var1.setColor(((Component)this).getBackground());
  135.          var1.drawLine(0, 0, var2.width - 1, 0);
  136.          var1.drawLine(0, 1, var2.width - 1, 1);
  137.          var1.drawLine(0, 2, var2.width - 1, 2);
  138.       }
  139.  
  140.    }
  141.  
  142.    public void disable() {
  143.       if (((Component)this).isEnabled()) {
  144.          ((Component)this).setFont(this.active);
  145.          super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
  146.          this.centerText(this.active);
  147.          ((Component)this).repaint();
  148.          super.disable();
  149.       }
  150.  
  151.    }
  152.  
  153.    public void enable() {
  154.       if (!((Component)this).isEnabled()) {
  155.          ((Component)this).setFont(this.inactive);
  156.          super.reshape(this.tab_x, this.tab_y, this.tab_width, this.tab_height);
  157.          this.centerText(this.inactive);
  158.          ((Component)this).repaint();
  159.          super.enable();
  160.       }
  161.  
  162.    }
  163.  
  164.    public void enable(boolean var1) {
  165.       if (var1) {
  166.          this.enable();
  167.       } else {
  168.          this.disable();
  169.       }
  170.    }
  171.  
  172.    public void SetDrawRight(boolean var1) {
  173.       this.m_bDrawRight = var1;
  174.       ((Component)this).repaint();
  175.    }
  176.  
  177.    public Dimension preferredSize() {
  178.       try {
  179.          if (super.img != null) {
  180.             return new Dimension(super.img.getWidth(this) + 4, super.img.getHeight(this) + 4);
  181.          } else if (this.label != null) {
  182.             FontMetrics var1 = ((Component)this).getFontMetrics(((Component)this).getFont());
  183.             int var2 = var1.stringWidth(this.label);
  184.             int var3 = var1.getMaxAscent();
  185.             var2 += 20;
  186.             var3 += 8 + var1.getMaxDescent();
  187.             return new Dimension(var2, var3);
  188.          } else {
  189.             return new Dimension(20, 20);
  190.          }
  191.       } catch (Exception var4) {
  192.          return new Dimension(20, 20);
  193.       }
  194.    }
  195.  
  196.    public void SetDrawLeft(boolean var1) {
  197.       this.m_bDrawLeft = var1;
  198.       ((Component)this).repaint();
  199.    }
  200. }
  201.